<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>食物卡路里查询</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            font-size: 16px;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        li {
            padding: 10px;
            border-bottom: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <input type="text" id="searchInput" placeholder="输入卡路里数量或食物名称">
    <a href="https://www.thepaper.cn/newsDetail_forward_8754575" target="_blank">查看每天少吃300kcal的研究</a>
    <a href="https://freeunitconvert.com/cn/energy/kcal-to-kj/" target="_blank">换算器</a>
    <a href="http://www.cdi.com.cn/Article/Detail?Id=19888" target="_blank"> 高端智库 </a>
    <ul id="resultList"></ul>
    
    <script>
        // 食物卡路里数据
        const foodCalories = {
            "苹果": 52,
            "香蕉": 89,
            "鸡蛋": 155,
            "牛奶": 64,
            "面包": 265,
            "牛角包" : 300,
            "40克奥利奥": 94,
            '慢跑3公里': 189,
            "慢跑5公里": 315,
            "慢跑10公里": 630,
            "基础代谢":2000,
        };

        const searchInput = document.getElementById('searchInput');
        const resultList = document.getElementById('resultList');

        searchInput.addEventListener('input', function() {
            const query = this.value.trim().toLowerCase();
            resultList.innerHTML = '';

            if (query === '') return;

            // 检查是否为数字（卡路里搜索）
            if (!isNaN(query)) {
                const calories = parseInt(query);
                for (const [food, cal] of Object.entries(foodCalories)) {
                    if (cal === calories) {
                        const li = document.createElement('li');
                        li.textContent = `${food}: ${cal} 大卡`;
                        resultList.appendChild(li);
                    }
                }
            } else {
                // 食物名称搜索
                for (const [food, cal] of Object.entries(foodCalories)) {
                    if (food.toLowerCase().includes(query)) {
                        const li = document.createElement('li');
                        li.textContent = `${food}: ${cal} 大卡`;
                        resultList.appendChild(li);
                    }
                }
            }
        });
    </script>
</body>
</html>